* create all couple -5 to +5
global data_folder "W:\intimate\data"
global log_folder "W:\intimate\dofiles\logs"
global result_folder "W:\intimate\results"

local var_list saikavv ututku ika

foreach y of numlist 2005/2015 { // for matching so only needed for subset of years
     
         
		use shnro `var_list' sukup using "D:\ready-made\FLEED_TOTAL\2016\fleed_kokonais_`y'.dta", clear
		keep if sukup=="2" //keep only female
        drop sukup 
		
		gen year_event=`y'
		gen yr_graduation=saikavv
		
		
		
			*Education variables
		gen level=substr(ututku, 1,1)
		destring level, replace
		
		gen birth_yr=`y'-ika


	    replace yr_graduation=birth_yr+16 if missing(ututku) & yr_graduation==. 
		replace yr_graduation=birth_yr+19 if level>=3 & level<=5 & yr_graduation==. 
		replace yr_graduation=birth_yr+23 if level>=6 & yr_graduation==. 
		
		gen yr_since_graduation=`y'-yr_graduation
		replace yr_since_graduation=0 if yr_since_graduation<0 
	    keep shnro year_event yr_since_graduation
		
		save "$data_folder\year_since_graduation_`y'.dta", replace
}





